package org.dreamwork.jasmine2.restful.client.gui.model;

import org.dreamwork.secure.AlgorithmMapping;
import org.dreamwork.secure.SecureContext;

import javax.swing.tree.DefaultMutableTreeNode;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 2014/12/9
 * Time: 0:34
 */
public class RootTreeNode extends DefaultMutableTreeNode {
    private String title;
    private String description;
    private SecureContext context;

    public RootTreeNode (Map<String, Object> map) {
        super (map.get ("title"));
        this.title = (String) map.get ("title");
        this.description = (String) map.get ("description");
        Map secure_context = (Map) map.get ("secure-context");
        context = new SecureContext ();
        for (Object key : secure_context.keySet ()) {
            String name = (String) key;
            Map m = (Map) secure_context.get (name);
            String uri = (String) m.get ("uri");
//            String jceName = (String) m.get ("jceName");
            if ("blockEncryption".equals (name)) {
                context.setBlockEncryption (AlgorithmMapping.find (uri));
            } else if ("keyTransport".equals (name)) {
                context.setKeyTransport (AlgorithmMapping.find (uri));
            } else if ("signature".equals (name)) {
                context.setSignature (AlgorithmMapping.find (uri));
            }
        }
    }

    public String getTitle () {
        return title;
    }

    public String getDescription () {
        return description;
    }

    public SecureContext getSecureContext () {
        return context;
    }
}
